var view = null;
var p;
var sp = {
	//头像的参数；
	headW: 50,
	headH: 50,
	headTop: 11,
	//昵称的参数
	nameTop: 15,
	nameleft: 72,
	nameSize: 14,
	//视频文字的参数
	name_Size: 12,
	//接受和拒绝图的参数
	imgjieW: 0,
	imgjieH: 0,
	imgjieTop: 0,
	imgjieRight: 0,
	imgjuRight: 0,
	//盒子的参数
	boxH: 70,
	boxW: 0,
	pageW: window.innerWidth,
	pageH: window.innerHeight
}

if(sp.pageW >= 320 && sp.pageW < 360) { //苹果5的尺寸
	sp.imgjieW = 50;
	sp.imgjieH = 25;
	sp.imgjieTop = sp.imgjieH / 2;
	sp.imgjieRight = 10;
	sp.imgjuRight = 66;
} else if(sp.pageW >= 360 && sp.pageW <= 420) {
	sp.imgjieW = 64;
	sp.imgjieH = 38;
	sp.imgjieTop = sp.imgjieH / 2;
	sp.imgjieRight = 10;
	sp.imgjuRight = 90;
} else if(sp.pageW >= 768 && sp.pageW <= 1000) {
	sp.imgjieW = 120;
	sp.imgjieH = 55;
	sp.imgjieTop = sp.imgjieH / 2;
	sp.imgjieRight = 15;
	sp.imgjuRight = 150;
	sp.nameleft = 110;
	sp.nameSize = 27;
	sp.nameTop = 20;
	sp.name_Size = 20;
	sp.headW = 80;
	sp.headH = 80;
	sp.headTop = 11;
	sp.boxH = 100;
} else if(sp.pageW > 1000) {
	sp.imgjieW = 164;
	sp.imgjieH = 84;
	sp.imgjieTop = sp.imgjieH / 2;
	sp.imgjieRight = 15;
	sp.imgjuRight = 200;
	sp.nameleft = 170;
	sp.nameSize = 46;
	sp.nameTop = 35;
	sp.name_Size = 40;
	sp.headW = 140;
	sp.headH = 140;
	sp.headTop = 20;
	sp.boxH = 180;
}
sp.boxW = window.innerWidth - 20;

function createView(Dsrc, nick_name) {
	view = new plus.nativeObj.View('test', {
		top: '10px',
		left: sp.headTop,
		height: sp.boxH,
		width: sp.boxW,
	});
	view.draw([{
			tag: 'rect',
			id: 'rect',
			position: {
				bottom: '0px',
				left: '0px',
				height: sp.boxH,
				width: sp.boxW,
			},
			rectStyles: {
				color: '#FFFFFF',
				radius: '10px'
			}
		}, {
			tag: 'img',
			id: 'head',
			src: Dsrc,
			position: {
				top: sp.headTop,
				left: sp.headTop,
				width: sp.headW,
				height: sp.headW
			}
		}, {
			tag: 'font',
			id: 'font1',
			text: '发来一个视频邀请',
			textStyles: {
				size: sp.name_Size,
				align: 'left',
				overflow: 'ellipsis',
				color:'#333'
			},
			position: {
				top: sp.nameTop,
				left: sp.nameleft,
				width: 'auto',
				height: 'auto'
			}
		}, {
			tag: 'font',
			id: 'font',
			text: nick_name,
			textStyles: {
				size: sp.nameSize,
				align: 'left',
				overflow: 'ellipsis'
			},
			position: {
				bottom: sp.nameTop,
				left: sp.nameleft,
				width: 'auto',
				height: 'auto'
			}
		}, {
			tag: 'img',
			id: 'head2',
			src: '/img/hello/reply_2.png',
			backgroundColor: '#dfdfdf',
			position: {
				top: sp.imgjieTop,
				right: sp.imgjieRight,
				width: sp.imgjieW,
				height: sp.imgjieH
			}
		},
		{
			tag: 'img',
			id: 'head4',
			src: '/img/hello/reply_1.png',
			position: {
				top: sp.imgjieTop,
				right: sp.imgjuRight,
				width: sp.imgjieW,
				height: sp.imgjieH
			}
		}
	]);
	view.show();
	addEventView()
	p = plus.audio.createPlayer("_www/img/audio/b.mp3");
	p.play();
	setTimeout(function() {
		if(view) {
			view.close();
			view = null;
			p.stop();
			p = plus.audio.createPlayer("_www/img/audio/c.mp3");
			p.play();
		}
	}, 20000)
}

function addEventView() {
	view.addEventListener("click", function(e) {
		var clientX = e.clientX; // 在View控件中的X坐标
		var clientY = e.clientY; // 在View控件中的Y坐标
		if(clientX > sp.headTop && clientX <= (sp.headTop + sp.headW) && sp.headTop < clientY && clientY <= (sp.headTop + sp.headH)) {

		} else if(clientX > (sp.boxW - sp.imgjieRight - sp.imgjieW) && clientX <= (sp.boxW - sp.imgjieRight) && clientY > sp.imgjieTop && clientY <= (sp.imgjieH + sp.imgjieTop)) {
			p.stop();
			p = plus.audio.createPlayer("_www/img/audio/c.mp3");
			p.play();
			mui.toast('VIP会员可免费接听');
			mui.openWindow({
				url: 'page/wallet.html',
				id: 'page/wallet.html',
				extras: {
					type: 2
				}
			})
			view.close();
			view = null;
		} else if(clientX > (sp.boxW - sp.imgjuRight - sp.imgjieW) && clientX <= (sp.boxW - sp.imgjuRight) && clientY > sp.imgjieTop && clientY <= (sp.imgjieH + sp.imgjieTop)) {
			view.close();
			view = null;
			p.stop();
			p = plus.audio.createPlayer("_www/img/audio/c.mp3");
			p.play();
		}
	}, false);
}